package uk.ac.glasgow.demosocs.tests;

import static org.junit.Assert.*;

import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import uk.ac.glasgow.demosocs.Election;
import uk.ac.glasgow.demosocs.VotingSystem;
import uk.ac.glasgow.demosocs.impl.VotingSystemStub;

public class CreateAndGetElection {

	private VotingSystem testVS;

	@Before
	public void setUp() throws Exception {
		testVS = new VotingSystemStub();
		
		testVS.setCurrentUser("admin", "p");
		testVS.createElection("oldE", "Simple_Plurality");
		testVS.editElection(new Date(), new Date(), new Date(), "Level_3");
	}

	@After
	public void tearDown() throws Exception {
		testVS = null;
	}

	@Test
	/** creates a new election 
	 * if successful then new current Election will be 
	 * different to the old current election
	 */
	public void testCreateAndGetCurrentElection() {
		
		Election e = testVS.getCurrentElection();
		
		testVS.setCurrentUser("admin", "p");
		testVS.createElection("testE", "Simple_Plurality");
		testVS.editElection(new Date(), new Date(), new Date(), "Level_3");
		Election newE = testVS.getCurrentElection();
		
		boolean result = newE.equals(e);
		assertFalse(result);
	}

	@Test
	/** non-admin user attempting to create election
	 */
	public void testCreateElectionNonAdmin() {
		
		Election e = testVS.getCurrentElection();
		
		testVS.setCurrentUser("2", "p");
		testVS.createElection("testE", "Simple_Plurality");
		
		Election newE = testVS.getCurrentElection();
		
		boolean result = newE.equals(e);
		assertTrue(result);
	}

}
